package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @Autowired
    private IDeviceService deviceService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定家人
     * @param memberElderDto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult bindFamilyMember(@RequestBody MemberElderDto memberElderDto){
        return toAjax(familyMemberElderService.bindFamilyMember(memberElderDto));
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    public R<List<FamilyMemberElderVo>> list(){
        List<FamilyMemberElderVo> list = familyMemberElderService.getAll();
        return R.ok(list);
    }
    //1.6 按周统计查询指标数据
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(@RequestParam String iotId, @RequestParam String functionId, @RequestParam Long startTime, @RequestParam Long endTime){
        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByWeek(iotId,functionId, startTime, endTime);
        return R.ok(list);
    }

    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByDay(@RequestParam("iotId") String iotId ,
                                                               @RequestParam("functionId") String functionId,
                                                               @RequestParam("startTime") Long startTime,
                                                               @RequestParam("endTime") Long endTime
                                                               )
    {
        List<DeviceDataGraphVo> list = deviceDataService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);

        return R.ok(list);
    }



    /**
     * 查看家人列表（分页查询）
     */
    @GetMapping("/list-by-page")
    public R<List<MemberElderVo>> listByPage(Integer pageNum,Integer pageSize){
        startPage();
        Long userId = UserThreadLocal.getUserId();
        List<MemberElderVo> list = familyMemberElderService.listByPage(userId);
        return R.ok(list);
    }

    /**
     * 查看健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public R<DevicePropertyVo> queryDevicePropertyStatus(@RequestBody DeviceDataDto deviceDataDto){
        /*List<PropertyStatusInfo> propertyStatusInfos = deviceService.selectHealthData(deviceDataDto);
        return R.ok(propertyStatusInfos);*/
        DevicePropertyVo devicePropertyVo = familyMemberService.selectHealthData(deviceDataDto);
        return R.ok(devicePropertyVo);
    }
}
